package daos;
import com.j256.ormlite.dao.*;
import com.j256.ormlite.stmt.*;
import com.j256.ormlite.support.*;
import entities.*;
import java.util.*;
import java.util.logging.*;
import java.util.logging.Logger;

/**
 * This Class is used to handle 
 * the DAO methods of the Access class 
 * @author Juanan JS juanantonios@gmail.com
 */
public class AccessDao
{
    private ConnectionSource objConnectionSource=null;
    
    /**
     * Constructor:
     * @param objConnectionSource_ 
     * An active instance of a ConnectionSource
     */
    public AccessDao(ConnectionSource objConnectionSource_)
    {
        this.objConnectionSource=objConnectionSource_;
    }
    
    /**
     * @param intGroup ID of the Group or role
     * @return A List of access of the Given group or null 
     * if the group doesn't exist
     */
    public List<AccAccess> findByGroupId(Integer intGroup)
    {
        List<AccAccess> objAccessList=null;
        try
        {
            //JS: do the user dao
            Dao<AccAccess, Integer> objUserDao = DaoManager.createDao(objConnectionSource, AccAccess.class);
            //JS: do the query for user login
            QueryBuilder<AccAccess, Integer> queryBuilder =objUserDao.queryBuilder();
            queryBuilder.where().eq(AccAccess.GRP_ID, intGroup);
            PreparedQuery<AccAccess> preparedQuery = queryBuilder.prepare();
            //JS: query for all accounts that have that login
            objAccessList = objUserDao.query(preparedQuery);
        } catch (Exception ex)
        {
            Logger.getLogger(UserDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        return objAccessList;
    }
}
